/**
 * @author zhoutao
 *  2010-11-6
 */
package com.jlt.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.commons.lang.StringUtils;

/**
 * @author zhoutao
 * 
 */
public class BaseSelectTag extends SimpleTagSupport {

	private String id;
	private String defaultValue;
	private Boolean nullOption = false;

	public void doTag() throws JspException {
		StringBuffer DicSelect = new StringBuffer();

		DicSelect.append("<select");

		if (StringUtils.isNotBlank(id)) {
			DicSelect.append(" id=\"" + id + "\" name=\"" + id + "\" class=\"combox\">");
		}

		if (nullOption) {
			DicSelect.append("<option value=\"0\">请选择</option>");
		}

		DicSelect.append("<option  value=\"A\"");
		if ("A".equalsIgnoreCase(defaultValue)) {
			DicSelect.append(" selected=\"selected=\"");
		}
		DicSelect.append(">可用</option>");
		DicSelect.append("<option  value=\"N\"");
		if ("N".equalsIgnoreCase(defaultValue)) {
			DicSelect.append(" selected=\"selected=\"");
		}
		DicSelect.append(">不可用</option>");
		DicSelect.append("</select>");

		try {
			getJspContext().getOut().write(DicSelect.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public Boolean getNullOption() {
		return nullOption;
	}

	public void setNullOption(Boolean nullOption) {
		this.nullOption = nullOption;
	}

}
